<template>
  <div class="cartcontrol">
    <div class="cart-decrease" v-show="food.count>0" v-on:click.stop.prevent="decreaseCart($event)">
      <!-- 一个层平移一个层滚动， -->
      <span class="inner icon-remove_circle_outline"></span>
    </div>
    <div class="cart-count" v-show="food.count>0">{{food.count}}</div>
    <div class="cart-add icon-add_circle" v-on:click.stop.prevent="addCart($event)"></div>
  </div>
</template>

<script type="text/ecmascript-6">
  import Vue from 'vue';

  export default {
    name: 'cartcontrol',
    props: {
      food: {
        type: Object
      }
    },
    methods: {
      addCart (event) {
        if (!event._constructed) {
          return;
        }
        if (!this.food.count) {
          Vue.set(this.food, 'count', 1);
        } else {
          this.food.count++;
        }
        console.log(this.$root.eventHub);
        this.$root.eventHub.$emit('cart.add', event.target);
      },
      decreaseCart (event) {
        if (!event._constructed) {
          return;
        }
        ;
        if (this.food.count) {
          this.food.count--;
        }
        ;
      }

    }

  };
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .cartcontrol
    font-size 0

    .cart-decrease
      display inline-block
      padding 6px

      .inner
        font-size 24px
        line-height 24px
        color: rgb(0, 160, 220)

    .cart-count
      display inline-block
      font-size 10px
      line-height 24px
      padding 6px
      color: rgb(147, 153, 159)

    .cart-add
      display inline-block
      padding 6px
      font-size 24px
      line-height 24px
      color: rgb(0, 160, 220)
</style>
